﻿$(document).ready(function () {
    var datasource = new kendo['data'].DataSource({
        type: 'json',
        serverPaging: true,
        serverSorting: true,
        pageSize: 10,
        transport: {
            read: {
                url: '../Handler/sysGroupsHandler.ashx?show=read',
                dataType: 'json'
            },
            update: {
                url: '../Handler/sysGroupsHandler.ashx?show=update',
                dataType: 'json',
                complete: function (data) {
                    //alert(data);
                    $('#groups-grid')['data']('kendoGrid')['dataSource']['read']();
                }
            },
            create: {
                url: '../Handler/sysGroupsHandler.ashx?show=create',
                dataType: 'json',
                complete: function (data) {
                    //alert(data);
                    $('#groups-grid')['data']('kendoGrid')['dataSource']['read']();
                }
            },
            destroy: {
                url: '../Handler/sysGroupsHandler.ashx?show=delete',
                dataType: 'json',
                complete: function (data) {
                    //alert(data.success);
                    $('#groups-grid')['data']('kendoGrid')['dataSource']['read']();
                }
            }
        },
        batch: true,
        schema: {
            data: 'data',
            total: 'pageSize',
            model: {
                id: 'GroupID',
                fields: {
                    GroupID: {
                        type: 'number'
                    },
                    GroupName: {
                        nullable: false
                    }
                }
            }
        }
    });

    $('#groups-grid').kendoGrid({
        dataSource: datasource,
        toolbar: ['create'],
        columns: [
            {
                command: ['edit', 'destroy'],
                title: '&nbsp;',
                width: 100,
                attributes: {
                    style: 'text-align: center'
                }
            },
            {
                title: 'Group',
                field: 'GroupName',
                width: 200
                , filterable: false

            }
            ],
        editable: 'inline',
        sortable: true,
        resizable: true,
        pageable: {
            refresh: true,
            pageSizes: true
        },
        selectable: 'row'
        , filterable: { extra: false, operators: { string: { startswith: "Contains"}} }

    });

    
    $('#search')['click'](function () {
        var _0xdf4cx6 = 'GroupName';
        var _0xdf4cx7 = $('#keyword')['val']();
        var grid = $('#groups-grid')['data']('kendoGrid');
        grid['dataSource']['transport']['options']['read']['url'] = '../Handler/GroupHandler.ashx?show=read&key=' + _0xdf4cx6 + '&word=' + _0xdf4cx7;
        grid['dataSource']['read']();
        return false;
    });
});


